﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Net;

namespace ZapHelper
{
    public class CookieWebClient : WebClient
    {

        public System.Net.CookieContainer CookieContainer { get; private set; }

        public CookieWebClient()
        {
            CookieContainer = new CookieContainer();
        }

        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest request = 
                base.GetWebRequest(address);

            if (request.GetType() == 
                    typeof(HttpWebRequest))
            {
                ((HttpWebRequest)request).CookieContainer = CookieContainer;
            }

            return request;
        }

    }

}
